package fgame.action
{
	import fgame.GameState;
	import fgame.unit.Actor3D;
	
	import flare.collisions.CollisionInfo;
	
	import flash.geom.Vector3D;
	
	/**
	 * 跳跃行动
	 */
	public class JumpFromAct extends MoveToAct
	{
		public function JumpFromAct(actor:Actor3D=null)
		{
			super(actor);
			this.animProperty="hurt";
			this._types=2;
		}
		
		override public function purpose(args:*):void
		{
			Debug.traceMe(args,"JumpFromAct.purpose");

			x=args.pos.x;
			y=args.pos.y;
			z=args.pos.z;
			rotation=args.rotation;
			target.x=x;
			target.y=z;
			
			if(this._actor.data && this._actor.data.speed)
				_speed=-int(_actor.data.speed)/1000;
			
			jumpValue=args.jumpValue;
			
			if(!isArrive())
				lookAtTarget();

		}
		
		override public function action(time:Number):void
		{
			
			var dot:Number=time-_lastFrameTime;
			_lastFrameTime=time;
			
			if(!_isArrive) //如果没有到达目标点
			{
				_lastDtTime+=dot;
				if(_lastDtTime>1000)
				{
					_lastDtTime=0;
					lookAtTarget();
				}
				
				if(!this.isArrive())
				{
					this.graphic.translateZ(_speed*dot); //没到达
				}else
				{
					graphic.setRotation(rotation.x,rotation.y,rotation.z);
				}
			}else
			{
				jumpValue -= 0.3;
				jumpValue *=0.9;
				this._graphic.y += jumpValue;

				_graphic.translateZ(_speed*dot);
				var from:Vector3D = graphic.localToGlobal( new Vector3D( 0, 50, 0 ) );
				var dir:Vector3D = graphic.getDown();
				rayCollisions=GameState.inst.sceneManager.rayCollision;
				if(rayCollisions.test(from,dir))
				{
					var info:CollisionInfo = rayCollisions.data[0];
					
					if ( _graphic.y <= info.point.y ) 
					{
						_graphic.y = info.point.y;
						this.complete();
					}
				}
			}

		}
		
		private var jumpValue:Number=0;
		private var rotation:Object;
		private var _speed:Number;
		
	}
}